package edu.gatech.blackjackai.carddata;

/**
 * GameState represents a full game of blackjack in progress. Three decks are used to keep track
 * of all of the cards in play. The GameState keeps track of the current count and how likely
 * it is that certain cards are going to be played.
 * @author Sean Gillespie
 * @version 1.0
 *
 */
public class GameState {
	
	public final int BLACKJACK_PAYOUT = 2;
	
	private Deck dealerDeck;
	private Deck tableDeck;
	private Deck discardDeck;
	private CardValue dealerCard;
	private double maxBet;
	private double minBet;
	private AIDataContainer player;
	
	/**
	 * Creates a new GameState with the given number of decks to play with and a given minimum and maxmimum bet.
	 * @param numDecks The number of decks to play with
	 */
	public GameState(int numDecks, double minBet, double maxBet) {
		dealerDeck = new Deck(numDecks);
		tableDeck = new Deck();
		discardDeck = new Deck();
		dealerCard = null;
		this.setMinBet(minBet);
		this.setMaxBet(maxBet);
		player = null;
	}
	
	/**
	 * Creates a new GameState with one deck with a minimum bet of 1 and maximum bet of 5.
	 */
	public GameState() {
		this(1, 1, 5);
	}

	/**
	 * Sets the AIDataContainer to the parameter.
	 * @param player The AIDataContainer to use.
	 */
	public void setAIDataContainer(AIDataContainer player) {
		this.player = player;
	}
	
	/**
	 * Dealt removes a card from the dealer's deck and adds it to the table deck. This is
	 * analogous to the dealing of a card from the deck to a player during the game.
	 * @param card The card that was dealt.
	 */
	public void dealt(CardValue card) {
		tableDeck.addCard(dealerDeck.removeCard(card));
		player.updateCount(card);
	}
	
	/**
	 * clearTable moves all cards from the table deck to the discard deck. This is analogous to
	 * the dealer discarding all cards that were used in a round of blackjack.
	 */
	public void clearTable() {
		discardDeck.addAll(tableDeck);
		tableDeck.clearDeck();
	}
	
	/**
	 * Deals a card to the player, removes the card from the dealer deck, and 
	 * @param card
	 */
	public void dealToPlayer(CardValue card) {
		player.cardIsGivenToPlayer(card);
		dealt(card);
	}
	
	public void setDealerCard(CardValue card) {
		dealerCard = card;
	}
	
	public CardValue getDealerCard() {
		return dealerCard;
	}

	public double getMaxBet() {
		return maxBet;
	}

	public void setMaxBet(double maxBet) {
		this.maxBet = maxBet;
	}

	public double getMinBet() {
		return minBet;
	}

	public void setMinBet(double minBet) {
		this.minBet = minBet;
	}
	
}
